package com.bawei.library_common.image.module

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.module.AppGlideModule

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/24 08:58
 * @Description : CacheGlideModule 重新配置Glide缓存大小
 */
@GlideModule
class CacheGlideModule: AppGlideModule() {
    override fun applyOptions(context: Context, builder: GlideBuilder) {
        //super.applyOptions(context, builder)
        //设置内存缓存大小：根据机器自动计算
//        var  memorySizeCalculator = MemorySizeCalculator.Builder(context).build()
//        builder.setMemoryCache(LruResourceCache(memorySizeCalculator.memoryCacheSize.toLong()))
        //设置内存缓存大小:10M
        builder.setMemoryCache(LruResourceCache(10*1024*1024))
        //设置磁盘缓存大小：500M 默认250M 设置磁盘缓存文件夹名称 "my_image" 默认 "image_manager_disk_cache"
        builder.setDiskCache(InternalCacheDiskCacheFactory(context,"my_image",500*1024*1024))//修

    }
}